<template>
<div>
    <div class="e-form">
        <BillTop @cancel="printHandel"></BillTop>
        <div class="tabs warningTabs">
             <el-tabs tab-position="left" v-model="tabsName" @tab-click="onChangeTab">
                <!-- 基本信息 -->
                <el-tab-pane label="基本信息" name="baseInfo" :disabled="clickTabFlag"></el-tab-pane>
                <el-tab-pane label="结算明细" name="changeDetail" :disabled="clickTabFlag"></el-tab-pane>
                <el-tab-pane label="服务费用" name="recommendedLessor" :disabled="clickTabFlag"></el-tab-pane>
                <el-tab-pane label="保证金" name="attach" :disabled="clickTabFlag"></el-tab-pane>
                <el-tab-pane label="附件信息" name="changeHistory" :disabled="clickTabFlag"></el-tab-pane>
                <el-tab-pane label="审核历史" name="auditHistory" :disabled="clickTabFlag"></el-tab-pane>
                <div>
                <div id="baseInfoCon" class="con">
                <div class="tabs-title" id="baseInfo">基本信息</div>
                <div style="width: 100%" class="form">
                <!-- 基本信息 -->
                <el-form ref="ruleForm" :model="formData" label-width="160px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="结算编号：" >
                           {{formData.billNo}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="机构：">
                           {{formData.orgName}}
                         </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="业务类型：">
                         {{formData.businessTypeValue}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="源单编号：">
                        <span>{{formData.sourceNo}}</span>
                        <span class="a"
                        @click="seeSourceOrder">查看</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="结算单位：">
                          {{formData.settleOrgName}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="结算类型：">
                         {{setSettleType}}
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="发票号：">
                           {{formData.invoiceNo}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="录入人员：">
                          {{formData.inputName}}
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="不含税金额(元)：" >
                             {{TotalSettlementAmount}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                         <el-form-item label="结算日期：">
                            {{formData.settleDate}}
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="税率：">
                            {{formData.taxRate}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="税价合计：">
                            {{totalTaxPrice}}
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="税额：">
                          {{formData.taxAmount}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="累计结算金额：">
                            {{cumulativeTotalSettlementAmount}}
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="服务费用(含税)：" >
                                {{TotalSettlementAmountService}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="单据来源：">
                          {{ billSourceData }}
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="冲预付款金额(元)：">
                              <el-checkbox disabled v-model="checkedBox">
                                    <span>{{formData.advanceChargeAmount}}</span>
                              </el-checkbox>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="验收编号：">
                          {{ formData.acceptanceNo }}
                         <span class="a"
                         @click="seeAcceptanceNumber">查看</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="冲个人借支：" >
                            <el-checkbox disabled
                            v-model="isTickPersonalBorrowing"></el-checkbox>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="终期结算：">
                            <el-checkbox disabled v-model="formData.isFinalSettle"
                            ></el-checkbox>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="冲个人借支金额(元)：" >
                          {{formData.rushPersonalBorrowingAmount}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="币种：">
                          {{formData.currency}}
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="冲销对象：" >
                           {{formData.reversalObjectName}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="本位币：">
                            {{ formData.baseCurName}}
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="本位币汇率：">
                        {{formData.baseCurRate}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="人名币汇率：" >
                            {{formData.rmbRate}}
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="借支人员：" >
                         {{formData.borrower}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="结算金额(本位币)：" >
                            {{baseCurAmount}}
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                     <el-col :span="12">
                        <el-form-item label="状态：" >
                            {{stateLable(formData.state)}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="传输财务共享：">
                            <span :class="isFontColor ? 'redFont' : 'greenFont'">{{shareLable(formData.transferFinancialShare)}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="备注：">
                            <el-input placeholder="" v-model="formData.remarks" class="input-with-select" type="textarea"
                            :rows="3" maxlength='500'>
                            <span>
                                {{formData.remarks}}
                            </span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-if='formData.state==5'>
                    <el-col :span="12">
                        <el-form-item label="作废原因：">
                           {{formData.nullifyReason}}
                        </el-form-item>
                    </el-col>
                     <el-col :span="12">
                        <el-form-item label="作废说明：">
                           {{formData.nullifyDescription}}
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-if='formData.state==5'>
                    <el-col :span="12">
                        <el-form-item label="作废人：">
                           {{formData.nullifyCreator}}
                        </el-form-item>
                    </el-col>
                     <el-col :span="12">
                        <el-form-item label="作废时间：">
                           {{formData.nullifyCreated}}
                        </el-form-item>
                    </el-col>
                </el-row>
                </el-form>
                    </div>
                    </div>
                    <!-- 结算明细 -->
                    <div id="changeDetailCon" class="con">
                        <div class="tabs-title" id="changeDetail">结算明细</div>
                        <div class="e-table">
                            <div class="top">
                                <div class="left">
                                </div>
                                 <div class="right">
                                    合计：{{TotalSettlementAmount}}
                                </div>
                            </div>
                           <div class="e-table">
                            <el-table
                                :data="acceptanceData"
                                border
                                ref="changeDetail"
                                style="width: 100%"
                                @cell-mouse-enter="cellMouseEnter"
                                @cell-mouse-leave="cellMouseLeave"
                                :header-cell-style="{ textAlign: 'center' }"
                                :cell-style="{ textAlign: 'center' }"
                                :tree-props="{
                                    children: 'children',
                                    hasChildren: 'hasChildren'
                                }"
                                row-key="uuid"
                                class="table"
                                :default-expand-all='true'
                                :max-height="$store.state.tableHeight"
                                v-sortTable="{ 'tableData': acceptanceData, '_this': this, 'ref': 'changeDetail' }"
                            >
                                <el-table-column fixed label="操作" width="70">
                                    <template slot-scope="{ row }">
                                        <div class="handle">
                                            <div style="cursor: pointer;"
                                            v-if='!row.children'>
                                            </div>
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="materialClassName"
                                    label="物资类别"
                                    fixed
                                    min-width="150"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="materialName"
                                    label="物资名称"
                                    fixed
                                    min-width="150"
                                >
                                </el-table-column>
                                <el-table-column prop="spec" label="规格" min-width="150">
                                </el-table-column>
                                <el-table-column prop="texture" label="材质"  min-width="150">
                                </el-table-column>
                                <el-table-column prop="unit" label="计量单位"  min-width="150">
                                </el-table-column>
                                <el-table-column
                                    label="未结算数量"
                                    min-width="150"
                                    prop="unsettleQuantity"
                                >
                                </el-table-column>

                                 <el-table-column
                                    label="结算数量"
                                    min-width="150"
                                    prop="quantity"
                                >
                                </el-table-column>
                                <el-table-column
                                    label="验收单价(元)"
                                    min-width="150"
                                    prop="price"
                                >
                                </el-table-column>

                                <el-table-column
                                    label="结算单价(元)"
                                    min-width="150"
                                    prop="settlePrice"
                                >
                                </el-table-column>

                                <el-table-column
                                    label="结算金额(元)"
                                    min-width="150"
                                    prop="taxExcludedAmount"
                                >
                                </el-table-column>

                                <el-table-column
                                    label="差额"
                                    min-width="150"
                                    prop="difference"
                                >
                                </el-table-column>

                                <el-table-column
                                    label="税额差额"
                                    min-width="200"
                                    prop="taxAmountDifference"
                                >
                                </el-table-column>
                            </el-table>
                        </div>
                        </div>
                    </div>
                    <!-- 服务费用 -->
                    <div id="serviceFyCon" class="con">
                        <div class="tabs-title" id="recommendedLessor">服务费用</div>
                        <div class="e-table" style="background-color: #fff">
                            <div class="top">
                                <div class="left">
                                </div>
                                <div class="right">
                                    合计：{{TotalSettlementAmountService}}
                                </div>
                            </div>
                            <div class="e-tree-table">
                                <el-table
                                    ref="tableDataServiceShowTable"
                                    key="tableRef"
                                    border
                                    style="width: 100%"
                                    row-key="id"
                                    :data="tableDataServiceShow"
                                    :cell-class-name="cellClsNm"
                                    @cell-mouse-enter="cellMouseEnter"
                                    @cell-mouse-leave="cellMouseLeave"
                                    class="table"
                                    :max-height="$store.state.tableHeight"
                                    v-sortTable="{ 'tableData': tableDataServiceShow, '_this': this, 'ref': 'tableDataServiceShowTable' }"
                                >
                                    <el-table-column label="序号" type="index" fixed width="55"> </el-table-column>
                                    <el-table-column label="合同编号" min-width="200" prop="contractNumber" show-overflow-tooltip>
                                    </el-table-column>
                                    <el-table-column label="结算单位" min-width="200" prop="settlementUnitName" show-overflow-tooltip>
                                    </el-table-column>
                                    <el-table-column label="发票编号" width="200" prop="invoiceNo" show-overflow-tooltip>
                                    </el-table-column>
                                    <el-table-column label="清单名称" width="150" prop="contractDtlName" show-overflow-tooltip>
                                    </el-table-column>
                                    <el-table-column label="数量" width="150" prop="quantity">
                                    </el-table-column>
                                    <el-table-column
                                        prop="price"
                                        label="单价(元)"
                                        width="100"
                                    >
                                    </el-table-column>
                                    <el-table-column label="金额(元)" width="150" prop="amount">
                                    </el-table-column>
                                    <el-table-column label="税率%" width="150" prop="taxRate">
                                    </el-table-column>
                                    <el-table-column label="税额(元)" width="150" prop="taxAmount">
                                    </el-table-column>
                                    <el-table-column label="税价合计(元)" width="150" prop="totalAmount"></el-table-column>
                                </el-table>
                            </div>
                        </div>
                    </div>
                    <!-- 保证金 -->
                    <div id="bzjCon" class="con">
                        <div class="tabs-title" id="attach">保证金</div>
                        <div class="e-table">
                            <div class="mainTitle"><i class="el-icon-d-arrow-right"></i>暂扣保证金</div>
                            <div class="e-tree-table">
                                <el-table
                                    ref="tableDataBzjShow1Table"
                                    key="tableRef"
                                    border
                                    style="width: 100%"
                                    row-key="returnDepositId"
                                    :data="tableDataBzjShow1"
                                    :cell-class-name="cellClsNm"
                                    @cell-mouse-enter="cellMouseEnter"
                                    @cell-mouse-leave="cellMouseLeave"
                                    class="table"
                                    :max-height="$store.state.tableHeight"
                                    v-sortTable="{ 'tableData': tableDataBzjShow1, '_this': this, 'ref': 'tableDataBzjShow1Table' }"
                                >
                                    <el-table-column label="序号" type="index" fixed width="55"> </el-table-column>
                                    <el-table-column label="名称" min-width="200" prop="returnDepositName" show-overflow-tooltip> </el-table-column>
                                    <el-table-column label="暂扣保证金(元)" width="200" prop="amount">
                                    </el-table-column>
                                    <el-table-column label="截止上期末暂扣保证金(元)" width="250" prop="amountBqm" show-overflow-tooltip> </el-table-column>
                                    <el-table-column label="截止本期末暂扣还保证金(元)" width="250" prop="amountSqm">
                                    </el-table-column>
                                    <el-table-column label="说明" min-width="150" prop="remarks">
                                        <template slot-scope="{ row }">
                                          <el-input placeholder="" v-model="row.remarks" class="input-with-select" type="textarea">
                                          </el-input>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </div>
                        </div>
                        <div class="e-table">
                            <div class="mainTitle"><i class="el-icon-d-arrow-right"></i>返还保证金</div>
                            <div class="e-tree-table">
                                <el-table
                                    ref="tableDataBzjShow2Table"
                                    key="tableRef"
                                    border
                                    style="width: 100%"
                                    row-key="returnDepositId"
                                    :data="tableDataBzjShow2"
                                    :cell-class-name="cellClsNm"
                                    @cell-mouse-enter="cellMouseEnter"
                                    @cell-mouse-leave="cellMouseLeave"
                                    class="table"
                                    :max-height="$store.state.tableHeight"
                                    v-sortTable="{ 'tableData': tableDataBzjShow2, '_this': this, 'ref': 'tableDataBzjShow2Table' }"
                                >
                                    <el-table-column label="序号" type="index" fixed width="55"> </el-table-column>
                                    <el-table-column label="名称" min-width="200" prop="returnDepositName" show-overflow-tooltip> </el-table-column>
                                    <el-table-column label="返还保证金(元)" width="200" prop="amount">
                                    </el-table-column>
                                    <el-table-column label="截止上期末未返还保证金(元)" width="250" prop="amountBqm" show-overflow-tooltip> </el-table-column>
                                    <el-table-column label="截止本期末未返还保证金(元)" width="250" prop="amountSqm">
                                    </el-table-column>
                                    <el-table-column label="说明" min-width="150" prop="remarks">
                                          <template slot-scope="{ row }">
                                          <el-input placeholder="" v-model="row.remarks" class="input-with-select" type="textarea">
                                          </el-input>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </div>
                        </div>
                    </div>
                    <div id="attachCon" class="con">
                        <div class="tabs-title" id="changeHistory">附件信息</div>
                        <attach-index :relationId="attachId" bucketName="facilityplan" isView />
                    </div>

                    <div id="auditHistoryCon" class="con">
                        <div class="tabs-title" id="auditHistory">审核历史</div>
                        <div class="e-table" v-if="auditParams.billId">
                            <ComAuditHistoryIndex
                                billType='6081'
                                ref="AuditHistoryRef"
                                :tableData.sync="auditHistoryTable"
                                @getAuditHistory="getAuditHistory"
                            />
                        </div>
                    </div>
                </div>
            </el-tabs>
            <div id="seat" :style="{ height: seatHeight + 'px' }"></div>
            <div class="buttons">
                  <el-button
                    type="primary"
                    class="btn-blue"
                    @click="printHandel"
                    size="small"
                    v-debounce
                    v-if="isView"
                    >关闭</el-button
                >
            </div>
         </div>
    </div>
</div>

</template>

<script>
import { mapState, mapMutations } from 'vuex'
import '@/utils/jquery.scrollTo.min'
import attachIndex from '@/components/common/attachIndex'
import ComAuditHistoryIndex from '@/pages/equipment/components/auditHistory/auditHistoryIndex'
import request from '@/api/settlementManagement/weeklyMaterialSettlement/purchaseSettlement.js'
// import { openAppClient,selectDataClient, hideLoading, throttle, formatDate,getUuid } from '@/utils/common'
import { hideLoading, throttle, formatDate, getUuid, openAppClient } from '@/utils/common'
export default {
    data () {
        return {
            isFontColor: true,
            auditHistoryTable: [], //审核历史表格
            tabsName: 'baseInfo',
            checkedBox: false, //冲预付款金额勾选参数
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            tableData: [],
            isView: false, //其他页面查看此页面时是否展示按钮
            formData: {
                //配置计划基础信息
                'acceptanceNo': '',
                'advanceChargeAmount': 0,
                'baseCurAmount': 0,
                'baseCurId': '',
                'baseCurName': '',
                'baseCurRate': 0,
                'billId': '',
                'billNo': '',
                'billSource': 0,
                'borrower': '',
                'businessTypeKey': 0,
                'businessTypeValue': '',
                'cumulativeSettleAmount': 0,
                'currency': '',
                'currencyId': '',
                'evaluationGrade': 0,
                'inputId': '',
                'inputName': '',
                'invoiceNo': '',
                'isFinalSettle': 0,
                'isRed': 0,
                'isRushAdvanceCharge': 0,
                'nullifyCreated': '',
                'nullifyCreator': '',
                'nullifyCreatorId': '',
                'nullifyDesciption': '',
                'nullifyReason': '',
                'orgId': '',
                'orgName': '',
                'parentId': '',
                'redStatus': 0,
                'remarks': '',
                'reversalObjectId': 0,
                'reversalObjectName': 0,
                'rmbAmount': 0,
                'rmbRate': 0,
                'rushPersonalBorrowing': 0,
                'rushPersonalBorrowingAmount': 0,
                'settleDate': formatDate(new Date(), 'yyyy-MM-dd'), //结算日期,
                'settleOrgName': '',
                'settleOrgId': '',
                'settleType': 0,
                'sourceId': '',
                'sourceNo': '',
                'state': 0,
                'taxAmount': 0,
                'taxExcluding': 0,
                'taxRate': 0,
                'totalTaxPrice': 0,
                'transferFinancialShare': 0,
                'transportUnitCost': 0,
                'workId': '',
                'settleAmount': 0
            },
            acceptanceData: [
                {
                    'children': [],
                    'topClassId': '',
                    'topClassName': '',
                    'totalAmount': 0,
                    'totalQuantity': 0,
                    'uuid': '12348asdzxxcuiwi'
                }
            ], //选择物资 结算明细
            tableDataBzj: [], // 保证金
            MouseEnterId: 0,
            billId: this.$route.query.billid,
            auditParams: {
                'billId': '',
                'billType': 6081,
                'freeNextUnitIndex': 0,
                'freeNextUser': '',
                'isPass': true,
                'isShareInAudit': true,
                'opinion': ''
            },
            billType: 6081,  //改为验结一体的billType
            winEvent: {},
            tableDataService: [], // 服务费用明细
            //是否勾选冲个人借支
            isTickPersonalBorrowing: false,
            //未冲销预付款
            tabArr: [], //用于验证功能列表中的必填项
        }
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo
        }),
        //根据状态值参数决定是否展示打印按钮
        stateLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.state
                const obj = state.find(x=>x.value == param)
                return (obj ?  obj.label :  '')
            }
        },
        //传输财务共享
        shareLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.shareFrom
                const obj = state.find(x=>x.value === param)
                return (obj ?  obj.label :  '')
            }
        },
        //当前单据状态
        state () {
            return this.formData.state
        },
        //附件信息获取当前billid
        attachId () {
            return this.$route.query.billid
        },
        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 258 - this.lastConHeight
        },
        //---------------基本信息-----------------//
        //当前单据来源
        billSourceData () {
            const obj = {
                0: '新增',
                1: '验结一体'
            }
            return obj[this.formData.billSource]
        },
        //当前结算类型
        setSettleType () {
            const obj = {
                1: '内部列账',
                2: '外来发票',
            }
            return obj[this.formData.settleType]
        },
        //税价合计
        totalTaxPrice () {
            return this.TotalSettlementAmount * 1 + this.formData.taxAmount * 1 + this.bondTotalAmount * 1 - (this.formData.advanceChargeAmount * 1 || 0)
        },
        //累计结算金额
        cumulativeTotalSettlementAmount () {
            return  (this.totalTaxPrice + this.TotalSettlementAmountService).toFixed(2) * 1
        },
        //本位币金额
        baseCurAmount () {
            return (this.cumulativeTotalSettlementAmount * (this.formData.baseCurRate || 0)).toFixed(2) * 1
        },
        //-----------------结算明细-----------------------//
        //计算差额
        getDifferenceData () {
            return row=>{
                const target = (Number(row.taxExcludedAmount) || 0) - (Number(row.acceptAmount) || 0)
                this.setDataRetainTwoDecimal(this.acceptanceData[0].children, row.dtlId, 'difference', target)
                return target
            }
        },
        //计算结算金额总额
        TotalSettlementAmount () {
            return this.acceptanceData[0].children.reduce((a, b)=>a + (Number(b.taxExcludedAmount) || 0), 0)
        },
        //-----------------服务费用---------------------//
        tableDataServiceShow () {
            return this.tableDataService.filter(item => item.changeType !== -1)
        },
        //税价合计总和
        TotalSettlementAmountService () {
            return this.tableDataServiceShow.reduce((a, b)=>a + (Number(b.totalAmount) || 0), 0)
        },
        //-------------------保证金--------------------//
        tableDataBzjShow1 () {
            return this.tableDataBzj.filter(item => item.changeType !== -1 && item.depositType === 1)
        },
        tableDataBzjShow2 () {
            return this.tableDataBzj.filter(item => item.changeType !== -1 && item.depositType === 2)
        },
        //本期金额总计
        bondTotalAmount () {
            return this.tableDataBzj.reduce((a, b)=>a + (Number(b.amount) || 0), 0)
        },

    },
    components: {
        attachIndex,
        ComAuditHistoryIndex,
    },
    created () {
        this.billId = this.$route.query.billid
        this.userId = localStorage.getItem('userId')
        this.isView = this.$route.query.isView ? false : true
    },
    mounted () {
        this.init()
        // 获取最后一个内容区域的高度，计算底部空白
        this.getLastConHeight()
        // 保存所有tabName
        const arr = ['baseInfo', 'changeDetail', 'recommendedLessor', 'attach', 'changeHistory', 'auditHistory']
        this.tabArr = arr
        let $idsTop = []
        const onScroll = () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            if (this.clickTabFlag) {
                return
            }
            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    const $item = document.getElementById(item)
                    let itemTop = null
                    if ($item) {
                        itemTop = $item.offsetTop
                    }
                    return itemTop
                })
            }
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                let item = $idsTop[i]
                if (scrollTop + 1 >= item) {
                    curLocal = i
                    break
                }
            }
            // 设置对应tabName
            this.tabsName = arr[curLocal]
        }
        this.winEvent.onScroll = onScroll
        window.addEventListener('scroll', this.winEvent.onScroll)
        this.screenWidth = document.documentElement.clientWidth - this.topHeight
        this.screenHeight = document.documentElement.clientHeight - this.topHeight
        const onResize = () => {
            this.screenWidth = document.documentElement.clientWidth - this.topHeight
            this.screenHeight = document.documentElement.clientHeight - this.topHeight
            $idsTop = arr.map(item => {
                const itemTop = document.getElementById(item).offsetTop
                return itemTop
            })
        }
        this.winEvent.onResize = throttle(onResize, 500)
        window.addEventListener('resize', this.winEvent.onResize)
    },
    beforeDestroy () {
        window.removeEventListener('scroll', this.winEvent.onScroll)
        window.removeEventListener('resize', this.winEvent.onResize)
    },
    methods: {
        ...mapMutations(['setSelectedInfo', 'setAuditParams']),
        //查看源单页面
        seeSourceOrder () {
            const urlObj = {
                '临时需用计划': '/momentNeedPlanShow',
                '物资采购合同': '/ctMaterialApplyShow',
                '调拨单': '/revolveAllocationShow'
            }
            const url = urlObj[this.formData.businessTypeValue]
            const billid = this.formData.sourceId
            openAppClient(
            `${url}?billid=${billid}&isview=true`, `${this.formData.businessTypeValue}`
            )
        },
        //查看验收编号
        seeAcceptanceNumber () {
            openAppClient(
            `/weeklyMaterialAccDetail?billid=${this.formData.acceptanceId}&isview=true`, '查看周材验收'
            )
        },
        //初始化数据
        init () {
            Promise.all([
                this.getInfo(),
                this.getDetailed(),
                this.getServiceFee(),
                this.getBond(),
            ]).finally(() => {
                hideLoading()
            })
        },
        //获取基本信息数据查看页面
        getInfo () {
            // 获取基本信息 tps
            request.queryBasicInformation({ billId: this.billId }).then(res=>{
                this.checkedBox = !!res.isRushAdvanceCharge
                this.auditParams.billId = res.acceptanceId
                this.isTickPersonalBorrowing = !!res.rushPersonalBorrowing
                this.formData = { ...res, isFinalSettle: !!res.isFinalSettle }
            })
        },
        //获取结算明细
        getDetailed () {
            request.getPurchaseSettlementDetailed({ billId: this.billId }).then(res=>{
                if(res.length > 0) {
                    res[0].uuid = getUuid()
                    res[0].children.forEach(item=>{
                        item.uuid = getUuid()
                    })
                    this.acceptanceData = res
                }
            })
        },
        //获取服务费用
        getServiceFee () {
            request.getPurchaseSettlementServiceFee({ billId: this.billId }).then(res=>{
                this.tableDataService = res
            })
        },
        //获取保证金
        getBond () {
            request.getPurchaseSettlementBond({ billId: this.billId, depositType: 1 }).then(res=>{
                this.tableDataBzj = res
            })
        },
        //刷新历史审核列表
        getAuditHistory () {
            request.checkBeforeAcceptance(this.auditParams).then(res=>{
                this.auditHistoryTable = res
            })
        },
        //切换左侧菜单
        onChangeTab (e) {
            const height  = $('#' + e.name).offset().top
            $.scrollTo(height - this.topHeight, 500)
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
        },
        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight () {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                const lastCon = document.getElementById('auditHistoryCon')
                if (lastCon) {
                    const lastConHeight = lastCon.offsetHeight
                    this.lastConHeight = lastConHeight
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },
        //操作成功后返回列表页面
        printHandel () {
            this.$router.replace('/purchaseSettlementList')
        },
        // elment表格事件
        cellMouseEnter (row) {
            this.MouseEnterId = row.billId
        },
        // elment表格事件
        cellMouseLeave () {
            this.MouseEnterId = 0
        },
        cellClsNm ({ column }) {
            if (column.label === '') {
                return 'fixed-left'
            }
        },
    },
}
</script>

<style lang="scss" scoped>
.form {
    margin-top: 10px;
}

.e-table {
    background: #fff;
}
.mainTitle {
    box-sizing: border-box;
    width: 100%;
    height: 40px;
    line-height: 40px;
    background: rgb(246, 246, 246);
    border: 1px solid rgb(236, 236, 236);
    margin: auto;
    margin-bottom: 15px;
    padding-left: 10px;
}
// ::v-deep input.el-input__inner {
//     border: 0;
// }
</style>
